﻿using System.Web.Mvc;
using Pay.DTO;
using Pay.IService;
using Pay.TO;

namespace Pay.Web.Areas.Admin.Controllers {
	[RouteArea("admin")]
	[RoutePrefix("member")]
	public class MemberController : AdminController {
		private IMerchantService _iMerchantService;

		public MemberController(IMerchantService iMerchantService) {
			_iMerchantService = iMerchantService;
		}

		public ActionResult Index() {
			return View();
		}

		public JsonResult Gets(MerchantQuery query) {
			var model = _iMerchantService.GetMerchant(query);
			return Json(ResultToJson.Json(model), JsonRequestBehavior.AllowGet);
		}

		public JsonResult Get(long id) {
			var model = _iMerchantService.GetMerchant(id);
			return Json(ResultToJson.Json(model), JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		public JsonResult Add(register_model dto) {
			var result = _iMerchantService.Register(dto);
			return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		public JsonResult ChangePwd(forget_model dto) {
			var result = _iMerchantService.Forget(dto);
			return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		public JsonResult Update(merchant_info dto) {
			int result = _iMerchantService.Update(dto);
			return Json(ResultToJson.Json(result > 0 ? " 保存成功" : "保存失败", result), JsonRequestBehavior.AllowGet);
		}

		[HttpDelete]
		public JsonResult Detele(long id) {
			int result = _iMerchantService.Delete(id);
			return Json(ResultToJson.Json(result > 0 ? " 保存成功" : "保存失败", result), JsonRequestBehavior.AllowGet);
		}

		/// <summary>
		/// 启用/禁用
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		[HttpPost]
		public JsonResult Disable(long id, bool disabled) {
			var user = _iMerchantService.GetMerchant(id);
			user.disabled = disabled;
			int result = _iMerchantService.Update(user);
			return Json(ResultToJson.Json(result > 0 ? " 保存成功" : "保存失败", result), JsonRequestBehavior.AllowGet);
		}
	}
}